import http from "./http";
/* eslint-disable */

/**
 * 注册
 * @param {string} account
 * @param {string} password
 */
export const register = async (account: string, password: string) => {
    const data = await http.post('register', {
        account,
        password,
    })
    return data
}

/**
 * 登录
 * @param {string} account
 * @param {string} password
 */
export const login = async (account: string, password: string) => {
    const data = await http.post('login', {
        account,
        password,
    })
    return data
}

/**
 * 写帖子
 * @param {string} title
 * @param {string} description
 * @param {string} content
 * @param {string[]} type
 * @param {string} time
 * @param {number} createdBy
 */
export const write = async (title: string, description: string, content: string, type: (string | number)[], time: string, createdBy: number) => {
    const data = await http.post('write', {
        title,
        description,
        content,
        type,
        time,
        createdBy
    })
    return data
}

/**
 * 更新帖子
 * @param {string} title
 * @param {string} description
 * @param {string} content
 * @param {string[]} type
 * @param {string} time
 * @param {number} id
 */
export const Rewrite = async (title: string, description: string, content: string, type: (string | number)[], time: string, id: number) => {
    const data = await http.post('Rewrite', {
        title,
        description,
        content,
        type,
        time,
        id
    })
    return data
}

/**
 * 获取帖子列表
 * @param {string} type
 */
export const getArticles = async (type?: string) => {
    const data = await http.get('getArticles', {
        type,
    })
    return data
}

/**
 * 获取该用户所有信息
 * @param {number} id
 */
export const getUserInfo = async (id: number) => {
    const data = await http.get('getUserInfo', {
        id,
    })
    return data
}

/**
 * 修改个人信息
 * @param {string} nickname
 * @param {string} id
 * @param {number} age
 * @param {string} gender
 * @param {string} school
 * @param {string} job
 */
export const changeUserInfo = async (nickname: string, id: number, age: number, gender: string, school: string, job: string) => {
    const data = await http.post('changeUserInfo', {
        nickname,
        id,
        age,
        gender,
        school,
        job
    })
    return data
}

/**
 * 文章、作者累计被浏览次数
 * @param {string} id
 * @param {string} createdBy
 */
export const beSeen = async (id: number, createdBy: number) => {
    const data = await http.post('beSeen', {
        id,
        createdBy,
    })
    return data
}

/**
 * 点赞功能
 * @param {string} id
 * @param {string} createdBy
 * @param {boolean} flag
 */
export const praise = async (id: number, createdBy: number, flag: boolean) => {
    const data = await http.post('praise', {
        id,
        createdBy,
        flag
    })
    return data
}

/**
 * 获得这篇帖子的所有信息
 * @param {number} id
 */
export const getArticleInfo = async (id: number | string) => {
    const data = await http.get('getArticleInfo', {
        id,
    })
    return data
}

/**
 * 删除一篇帖子
 * @param {string} id
 */
export const deleteArticle = async (id: number) => {
    const data = await http.delete('deleteArticle', {
        id,
    })
    return data
}

/**
 * 评论
 * @param {string} comment
 * @param {string} articleId
 * @param {string} createdById
 * @param {string} time
 */
export const comment = async (comment: string, articleId: number, createdById: number, time: string) => {
    const data = await http.post('comment', {
        comment,
        articleId,
        createdById,
        time
    })
    return data
}

/**
 * 获取一篇帖子的所有评论
 * @param {number} id
 */
export const getArticleComments = async (articleId: number) => {
    const data = await http.get('getArticleComments', {
        articleId
    })
    return data
}